//3.1渲染轮播图
async function getBanners() {

    //ajax请求是异步的。是不阻止代码向下运行的。
    let { result: result1 } = await myAjax({
        url: '/api/banners'
    })
    console.log(result1.result, '拿到了banner数据')
    //3.2 拼接字符串
    let arr = '' //图片li
    let arrr = ''//圆点的li

    result1.result.forEach((item, index) => {
        // console.log(item)
        arr += `<li>${item.title}</li>`
        arrr += `<li><img src="${item.image_src}" alt=""></li>`
    })
    $('#baa').html(arr)
    $('#bnn').html(arrr)
    lunBoTu()

}
getBanners()
//4.1 渲染同步课程
async function getTBCourse() {

    //4.2 发送ajax请求
    let { result } = await myAjax({
        url: '/api/courseinfo',
        data: {
            type: 1
        }
    })
    console.log(result.result, '同步课程')
    let tbStr = ''
    result.result.forEach(item => {
        tbStr += `
           
            <li a=${item.cid}">
                <a href="pages/videoDetail.html?id=${item.cid}">    
                   
                    <div class="top">
                        <span class="rj">人教版</span>
                        <img src="${item.image_src}" alt="" class="m">
                        <p>学科：英语</p>
                    </div>
                    <div class="bottom">
                        <div class="left">
                            <span>行政管理专业班</span>
                            <span class="time">地区：北京</span>
                        </div>
                        <div class="right">${ item.price == 0 ? '免费学习' : item.price + '元'}</div>
                    </div>
                </a>
            </li>
        `
    })
    $('#conton').html(tbStr)
}

getTBCourse()

//精品课程
async function getTbcourses() {

    //4.2 发送ajax请求
    let { result } = await myAjax({
        url: '/api/courseinfo',
        data: {
            type: 2
        }
    })
    console.log(result.result, '精品课程')
    let tbStr1 = ''
    result.result.forEach(item => {
        tbStr1 += `
           
            <li a=${item.cid}">
                <a href="pages/videoDetail.html?id=${item.cid}">    
                   
                    <div class="top">
                        <span class="rj">人教版</span>
                        <img src="${item.image_src}" alt="" class="m">
                        <p>学科：英语</p>
                    </div>
                    <div class="bottom">
                        <div class="left">
                            <span>行政管理专业班</span>
                            <span class="time">地区：北京</span>
                        </div>
                        <div class="right">${ item.price == 0 ? '免费学习' : item.price + '元'}</div>
                    </div>
                </a>
            </li>
        `
    })
    $('#cont').html(tbStr1)
}

getTbcourses()

//点击搜索按钮跳转到搜索页面
$('#btn_search').on('click', () => {    // alert('ok')
    // window.open
    let value = $('#search_txt').val()

    if (!value) {
        alert('请输入关键字')
        return
    }

    location.href = 'pages/search_list.html?keyword=' + value
})



















    // ; (async () => {
    //     //获取数据

    //     // let { result: result2 } = await myAjax({
    //     //     url: '/api/courseinfo'
    //     // })
    //     let { result: result3 } = await myAjax({
    //         url: '/api/tbcourses'
    //     })
//         console.log();


//         //同步课程
//         let conton = document.getElementById('conton')

//         let str = ''
//         for (var i = 0; i < result2.result.length; i++) {
//             str += `
//         <li> 
//         <div class="top">
//         <span class="rj">${ result2.result[i].type_name}</span>
//         <img src="./img/index/banner${ result2.result[i].image_src}" alt="" class="m">
//         <p>学科：${ result2.result[i].subject_name}</p>
//         </div>
//         <div class="bottom">
//         <div class="left">
//             <span>${ result2.result[i].title}</span>
//             <span class="time">地区：${ result2.result[i].area_name}</span>
//         </div>
//         <div class="right">${result2.result[i].price == 0 ? '免费学习' : result2.result[i].price + '元'}</div>
//     </div>
//     </li>`
//             $('#conton').on('click', 'li', function () {
//                 location.href = 'pages/videoDetail.html?id=${ result2.result.cid}'
//             })
//         }
//         conton.innerHTML = str
//         // <a href="videoDetail.html?id=${result2.result[i].cid}"> 
//         // conton.onclick=function(){
//         //     location.href = 'pages/videoDetail.html?id=${ result2.result.cid}' + value
//         // }

//         //精品课程
//         let cont = document.getElementById('cont')
//         let str1 = ''
//         for (var i = 0; i < result3.result.length; i++) {
//             str1 += `
//         <li>
//         <div class="top">
//         <span class="rj">人教版</span>
//         <img src="./img/index/banner${ result2.result[i].image_src}" alt="" class="m">
//         <p>学科：${result3.result[i].subject_name}</p>
//     </div>
//     <div class="bottom">
//         <div class="left">
//             <span>${result3.result[i].title}</span>
//             <span class="time">地区：${result3.result[i].area_name}</span>
//         </div>
//         <div class="right">${result3.result[i].price == 0 ? '免费学习' : result3.result[i].price + '元'}</div>
//     </div>
// </li> `
//         }
//         cont.innerHTML = str1
//     })()


